package com.yzf.demo.demo.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

/**
 * Created by 于占峰 on 2020/4/5/005.
 * 基于内存的字节输入输出
 */
public class MemeryDemo {

    public static void main(String[] args) {
        String str = "Hell Word";
        //从内存中读取数据
        ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
        //写出到内存中
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int len = 0;
        while ((len = bais.read()) != -1) {
            //写出 -- Character.toUpperCase 转为大写
            baos.write(Character.toUpperCase(len));
        }
        System.out.println(baos.toString());
    }
}
